<?php
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT'].'/');
$path = ROOT_DIR.'setting.php';
$settingsContent = file_get_contents($path);
$aikey = $_POST['ai_key'];
$aisecret = $_POST['ai_secret'];
$newSettingMailArray = <<<EOT
\$ai_array = array( //AI配置-天工大模型
    'ai_key' => '$aikey', //key
    'ai_secret' => '$aisecret', //secret
);
EOT;
$pattern = '/\$ai_array = array\(.*?\);/s';
$replacement = $newSettingMailArray;
$updatedSettingsContent = preg_replace($pattern, $replacement, $settingsContent);
file_put_contents($path, $updatedSettingsContent);
echo '<script>alert("修改成功");window.location.href="../../pluginset.php?s=ai";</script>';